using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Entities : MonoBehaviour
{
    [SerializeField]
    protected bool doStartOutOfMap;
    [SerializeField]
    protected bool doMovingWithMap;
    [SerializeField]
    protected bool doMovingWithDashingPlayer;
    [SerializeField]
    protected bool doSlowDown;
    [SerializeField]
    private float speedMultiple;

    protected void OnEnable()
    {
        if (doStartOutOfMap)
        {
            transform.position = new Vector3(Camera.main.ViewportToWorldPoint(new Vector3(1.1f, 0, 0)).x, transform.position.y, 0);
        }
        if (!doSlowDown)
        {
            speedMultiple = 1f;
        }
    }

    protected void FixedUpdate()
    {
        var viewportPosition = Camera.main.WorldToViewportPoint(gameObject.transform.position);
        if (viewportPosition.x < -0.1f)
        {
            GameObjectsPool.instance.RecoverItem(gameObject);
        }

        if (doMovingWithMap)
        {
            transform.position += GameManager.instance.CurrentGameSpeed * speedMultiple * Time.fixedDeltaTime * Vector3.left;
            return;
        }

        if (doMovingWithDashingPlayer)
        {
            transform.position += (GameManager.instance.CurrentGameSpeed - GameManager.instance.BaseGameSpeed) * speedMultiple * Time.fixedDeltaTime * Vector3.left;
        }
    }
}
